//
//  SlideBackViewController.m
//  JianChaRiBao
//
//  Created by yuzhou on 13-5-20.
//  Copyright (c) 2013年 wzyk. All rights reserved.
//

#import "SwipeBackViewController.h"

@interface SwipeBackViewController ()
{
    UISwipeGestureRecognizer *swipeGesture;
    UISwipeGestureRecognizer *swipeLeft;

    ABSpringLoadingView *abLoadingView;
}
@end

@implementation SwipeBackViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
	// Do any additional setup after loading the view.
    if (shouldSwipeBack && swipeGesture == nil) {
        swipeGesture = [[[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeBack)] autorelease];
        swipeGesture.direction = UISwipeGestureRecognizerDirectionRight;
        [self.view addGestureRecognizer:swipeGesture];
    }
    if (swipeLeft == nil && needSwipNext == YES) {
        swipeLeft = [[[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeLeft)] autorelease];
        swipeLeft.direction = UISwipeGestureRecognizerDirectionLeft;
        [self.view addGestureRecognizer:swipeLeft];
    }
}

- (void)swipeBack
{
    if (shouldSwipeBack) {
        [self.navigationController popViewControllerAnimated:YES];
    }
}

-(void)swipeLeft{
    
}

- (void)showABLoadingView
{
    if (abLoadingView.superview) {
        return;
    }
    if (abLoadingView == nil) {
        abLoadingView = [[[ABSpringLoadingView alloc] initWithFrame:self.view.frame] autorelease];
        UITapGestureRecognizer *tap = [[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(removeloadingView)] autorelease];
        [abLoadingView addGestureRecognizer:tap];
    }
    abLoadingView.alpha = 0;
    [self.view addSubview:abLoadingView];
    [UIView animateWithDuration:0.3 animations:^{
        abLoadingView.alpha = 1;
    }];
}

- (void)removeABLoadingView
{
    if (abLoadingView) {
        [UIView animateWithDuration:0.3 animations:^{
            abLoadingView.alpha = 0;
        } completion:^(BOOL finished) {
            [abLoadingView removeFromSuperview];
            abLoadingView = nil;
        }];
    }
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
